<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：  算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 杂项运算符  本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。  算术运算符下表显示了 C 语言支持的所有算术运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：    运算符 描述">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="C 运算符">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/01/09/c09/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：  算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 杂项运算符  本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。  算术运算符下表显示了 C 语言支持的所有算术运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：    运算符 描述">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-01-18T03:53:42.111Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="C 运算符">
<meta name="twitter:description" content="运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：  算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 杂项运算符  本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。  算术运算符下表显示了 C 语言支持的所有算术运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：    运算符 描述">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/01/09/c09/">





  <title>C 运算符 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/01/09/c09/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">C 运算符</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-01-09T20:35:45+08:00">
                2015-01-09
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/C语言教程/" itemprop="url" rel="index">
                    <span itemprop="name">C语言教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：</p>
<ul>
<li>算术运算符</li>
<li>关系运算符</li>
<li>逻辑运算符</li>
<li>位运算符</li>
<li>赋值运算符</li>
<li>杂项运算符</li>
</ul>
<p>本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。</p>
<hr>
<h4 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h4><p>下表显示了 C 语言支持的所有算术运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>+</td>
<td>把两个操作数相加</td>
<td>A + B 将得到 30</td>
</tr>
<tr>
<td>-</td>
<td>从第一个操作数中减去第二个操作数</td>
<td>A - B 将得到 -10</td>
</tr>
<tr>
<td>*</td>
<td>把两个操作数相乘</td>
<td>A * B 将得到 200</td>
</tr>
<tr>
<td>/</td>
<td>分子除以分母</td>
<td>B / A 将得到 2</td>
</tr>
<tr>
<td>%</td>
<td>取模运算符，整除后的余数</td>
<td>B % A 将得到 0</td>
</tr>
<tr>
<td>++</td>
<td>自增运算符，整数值增加 1</td>
<td>A++ 将得到 11</td>
</tr>
<tr>
<td>–</td>
<td>自减运算符，整数值减少 1</td>
<td>A– 将得到 9</td>
</tr>
</tbody>
</table>
<h5 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的算术运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 21;</span><br><span class="line">   int b = 10;</span><br><span class="line">   int c ;</span><br><span class="line"> </span><br><span class="line">   c = a + b;</span><br><span class="line">   printf(&quot;Line 1 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a - b;</span><br><span class="line">   printf(&quot;Line 2 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a * b;</span><br><span class="line">   printf(&quot;Line 3 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a / b;</span><br><span class="line">   printf(&quot;Line 4 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a % b;</span><br><span class="line">   printf(&quot;Line 5 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a++;  // 赋值后再加 1 ，c 为 21，a 为 22</span><br><span class="line">   printf(&quot;Line 6 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   c = a--;  // 赋值后再减 1 ，c 为 22 ，a 为 21</span><br><span class="line">   printf(&quot;Line 7 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - c 的值是 31 <br><br>Line 2 - c 的值是 11 <br><br>Line 3 - c 的值是 210 <br><br>Line 4 - c 的值是 2 <br><br>Line 5 - c 的值是 1 <br><br>Line 6 - c 的值是 21 <br><br>Line 7 - c 的值是 22 <br></p>
</blockquote>
<p>以下实例演示了 a++ 与 ++a 的区别：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">   int c;</span><br><span class="line">   int a = 10;</span><br><span class="line">   c = a++; </span><br><span class="line">   printf(&quot;先赋值后运算：\n&quot;);</span><br><span class="line">   printf(&quot;Line 1 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   printf(&quot;Line 2 - a 的值是 %d\n&quot;, a );</span><br><span class="line">   a = 10;</span><br><span class="line">   c = a--; </span><br><span class="line">   printf(&quot;Line 3 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   printf(&quot;Line 4 - a 的值是 %d\n&quot;, a );</span><br><span class="line"> </span><br><span class="line">   printf(&quot;先运算后赋值：\n&quot;);</span><br><span class="line">   a = 10;</span><br><span class="line">   c = ++a; </span><br><span class="line">   printf(&quot;Line 5 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   printf(&quot;Line 6 - a 的值是 %d\n&quot;, a );</span><br><span class="line">   a = 10;</span><br><span class="line">   c = --a; </span><br><span class="line">   printf(&quot;Line 7 - c 的值是 %d\n&quot;, c );</span><br><span class="line">   printf(&quot;Line 8 - a 的值是 %d\n&quot;, a );</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上程序执行输出结果为：</p>
<blockquote>
<p>先赋值后运算： <br><br>Line 1 - c 的值是 10 <br><br>Line 2 - a 的值是 11 <br><br>Line 3 - c 的值是 10 <br><br>Line 4 - a 的值是 9 <br><br>先运算后赋值： <br><br>Line 5 - c 的值是 11 <br><br>Line 6 - a 的值是 11 <br><br>Line 7 - c 的值是 9 <br><br>Line 8 - a 的值是 9 <br></p>
</blockquote>
<hr>
<h4 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h4><p>下表显示了 C 语言支持的所有关系运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>==</td>
<td>检查两个操作数的值是否相等，如果相等则条件为真。</td>
<td>(A == B) 不为真。</td>
</tr>
<tr>
<td>!=</td>
<td>检查两个操作数的值是否相等，如果不相等则条件为真。</td>
<td>(A != B) 为真。</td>
</tr>
<tr>
<td>&gt;</td>
<td>检查左操作数的值是否大于右操作数的值，如果是则条件为真。</td>
<td>(A &gt; B) 不为真。</td>
</tr>
<tr>
<td>&lt;</td>
<td>检查左操作数的值是否小于右操作数的值，如果是则条件为真。</td>
<td>(A &lt; B) 为真。</td>
</tr>
<tr>
<td>&gt;=</td>
<td>检查左操作数的值是否大于或等于右操作数的值，如果是则条件为真。</td>
<td>(A &gt;= B) 不为真。</td>
</tr>
<tr>
<td>&lt;=</td>
<td>检查左操作数的值是否小于或等于右操作数的值，如果是则条件为真。</td>
<td>(A &lt;= B) 为真。</td>
</tr>
</tbody>
</table>
<h5 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的关系运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">&amp;#35;include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 21;</span><br><span class="line">   int b = 10;</span><br><span class="line">   int c ;</span><br><span class="line"> </span><br><span class="line">   if( a == b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 1 - a 等于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   else</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 1 - a 不等于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   if ( a &lt; b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 2 - a 小于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   else</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 2 - a 不小于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   if ( a &gt; b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 3 - a 大于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   else</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 3 - a 不大于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   /* 改变 a 和 b 的值 */</span><br><span class="line">   a = 5;</span><br><span class="line">   b = 20;</span><br><span class="line">   if ( a &lt;= b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 4 - a 小于或等于 b\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   if ( b &gt;= a )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 5 - b 大于或等于 a\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - a 不等于 b <br><br>Line 2 - a 不小于 b <br><br>Line 3 - a 大于 b <br><br>Line 4 - a 小于或等于 b <br><br>Line 5 - b 大于或等于 a <br></p>
</blockquote>
<hr>
<h4 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h4><p>下表显示了 C 语言支持的所有关系逻辑运算符。假设变量 A 的值为 1，变量 B 的值为 0，则：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;&amp;</td>
<td>称为逻辑与运算符。如果两个操作数都非零，则条件为真。    (A &amp;&amp; B) 为假。</td>
</tr>
<tr>
<td>&#124;&#124;</td>
<td>称为逻辑或运算符。如果两个操作数中有任意一个非零，则条件为真。</td>
<td>(A &#124;&#124; B) 为真。</td>
</tr>
<tr>
<td>!</td>
<td>称为逻辑非运算符。用来逆转操作数的逻辑状态。如果条件为真则逻辑非运算符将使其为假。</td>
<td>!(A &amp;&amp; B) 为真。</td>
</tr>
</tbody>
</table>
<h5 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的逻辑运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 5;</span><br><span class="line">   int b = 20;</span><br><span class="line">   int c ;</span><br><span class="line"> </span><br><span class="line">   if ( a &amp;&amp; b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 1 - 条件为真\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   if ( a || b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 2 - 条件为真\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   /* 改变 a 和 b 的值 */</span><br><span class="line">   a = 0;</span><br><span class="line">   b = 10;</span><br><span class="line">   if ( a &amp;&amp; b )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 3 - 条件为真\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   else</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 3 - 条件不为真\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">   if ( !(a &amp;&amp; b) )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;Line 4 - 条件为真\n&quot; );</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - 条件为真 <br><br>Line 2 - 条件为真 <br><br>Line 3 - 条件不为真 <br><br>Line 4 - 条件为真 <br></p>
</blockquote>
<hr>
<h4 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h4><p>位运算符作用于位，并逐位执行操作。&amp;、 | 和 ^ 的真值表如下所示：</p>
<table>
<thead>
<tr>
<th>p</th>
<th>q</th>
<th>p &amp; q</th>
<th>p &#124; q</th>
<th>p ^ q</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>假设如果 A = 60，且 B = 13，现在以二进制格式表示，它们如下所示：</p>
<blockquote>
<p>A = 0011 1100</p>
</blockquote>
<blockquote>
<p>B = 0000 1101</p>
</blockquote>
<blockquote>
<p>A&amp;B = 0000 1100</p>
</blockquote>
<blockquote>
<p>A|B = 0011 1101</p>
</blockquote>
<blockquote>
<p>A^B = 0011 0001</p>
</blockquote>
<blockquote>
<p>~A  = 1100 0011</p>
</blockquote>
<p>下表显示了 C 语言支持的位运算符。假设变量 A 的值为 60，变量 B 的值为 13，则：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;</td>
<td>按位与操作，按二进制位进行”与”运算。运算规则：<br>0&amp;0=0;<br>0&amp;1=0;<br>1&amp;0=0;<br>1&amp;1=1;</td>
<td>(A &amp; B) 将得到 12，即为 0000 1100</td>
</tr>
<tr>
<td>&#124;</td>
<td>按位或运算符，按二进制位进行”或”运算。运算规则：<br>0&#124;0=0;<br>0&#124;1=1;<br>1&#124;0=1;<br>1&#124;1=1;</td>
<td>(A &#124; B) 将得到 61，即为 0011 1101</td>
</tr>
<tr>
<td>^</td>
<td>异或运算符，按二进制位进行”异或”运算。运算规则：<br>0^0=0;<br>0^1=1;<br>1^0=1;<br>1^1=0;</td>
<td>(A ^ B) 将得到 49，即为 0011 0001</td>
</tr>
<tr>
<td>~</td>
<td>取反运算符，按二进制位进行”取反”运算。运算规则：<br>~1=0;<br>~0=1;</td>
<td>(~A ) 将得到 -61，即为 1100 0011，一个有符号二进制数的补码形式。</td>
</tr>
<tr>
<td>&lt;&lt;</td>
<td>二进制左移运算符。将一个运算对象的各二进制位全部左移若干位（左边的二进制位丢弃，右边补0）。</td>
<td>A &lt;&lt; 2 将得到 240，即为 1111 0000</td>
</tr>
<tr>
<td>&gt;&gt;</td>
<td>二进制右移运算符。将一个数的各二进制位全部右移若干位，正数左补0，负数左补1，右边丢弃。</td>
<td>A &gt;&gt; 2 将得到 15，即为 0000 1111</td>
</tr>
</tbody>
</table>
<h5 id="实例-3"><a href="#实例-3" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的位运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line"> </span><br><span class="line">   unsigned int a = 60;    /* 60 = 0011 1100 */  </span><br><span class="line">   unsigned int b = 13;    /* 13 = 0000 1101 */</span><br><span class="line">   int c = 0;           </span><br><span class="line"> </span><br><span class="line">   c = a &amp; b;       /* 12 = 0000 1100 */ </span><br><span class="line">   printf(&quot;Line 1 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c = a | b;       /* 61 = 0011 1101 */</span><br><span class="line">   printf(&quot;Line 2 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c = a ^ b;       /* 49 = 0011 0001 */</span><br><span class="line">   printf(&quot;Line 3 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c = ~a;          /*-61 = 1100 0011 */</span><br><span class="line">   printf(&quot;Line 4 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c = a &lt;&lt; 2;     /* 240 = 1111 0000 */</span><br><span class="line">   printf(&quot;Line 5 - c 的值是 %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c = a &gt;&gt; 2;     /* 15 = 0000 1111 */</span><br><span class="line">   printf(&quot;Line 6 - c 的值是 %d\n&quot;, c );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - c 的值是 12 <br><br>Line 2 - c 的值是 61 <br><br>Line 3 - c 的值是 49 <br><br>Line 4 - c 的值是 -61 <br><br>Line 5 - c 的值是 240 <br><br>Line 6 - c 的值是 15 <br></p>
</blockquote>
<hr>
<h4 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h4><p>下表列出了 C 语言支持的赋值运算符：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>=</td>
<td>简单的赋值运算符，把右边操作数的值赋给左边操作数</td>
<td>C = A + B 将把 A + B 的值赋给 C</td>
</tr>
<tr>
<td>+=</td>
<td>加且赋值运算符，把右边操作数加上左边操作数的结果赋值给左边操作数</td>
<td>C += A 相当于 C = C + A</td>
</tr>
<tr>
<td>-=</td>
<td>减且赋值运算符，把左边操作数减去右边操作数的结果赋值给左边操作数</td>
<td>C -= A 相当于 C = C - A</td>
</tr>
<tr>
<td>*=</td>
<td>乘且赋值运算符，把右边操作数乘以左边操作数的结果赋值给左边操作数</td>
<td>C <em>= A 相当于 C = C </em> A</td>
</tr>
<tr>
<td>/=</td>
<td>除且赋值运算符，把左边操作数除以右边操作数的结果赋值给左边操作数</td>
<td>C /= A 相当于 C = C / A</td>
</tr>
<tr>
<td>%=</td>
<td>求模且赋值运算符，求两个操作数的模赋值给左边操作数</td>
<td>C %= A 相当于 C = C % A</td>
</tr>
<tr>
<td>&lt;&lt;=</td>
<td>左移且赋值运算符</td>
<td>C &lt;&lt;= 2 等同于 C = C &lt;&lt; 2</td>
</tr>
<tr>
<td>&gt;&gt;=</td>
<td>右移且赋值运算符</td>
<td>C &gt;&gt;= 2 等同于 C = C &gt;&gt; 2</td>
</tr>
<tr>
<td>&amp;=</td>
<td>按位与且赋值运算符</td>
<td>C &amp;= 2 等同于 C = C &amp; 2</td>
</tr>
<tr>
<td>^=</td>
<td>按位异或且赋值运算符</td>
<td>C ^= 2 等同于 C = C ^ 2</td>
</tr>
<tr>
<td>&#124;=</td>
<td>按位或且赋值运算符</td>
<td>C &#124;= 2 等同于 C = C &#124; 2</td>
</tr>
</tbody>
</table>
<h5 id="实例-4"><a href="#实例-4" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的赋值运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 21;</span><br><span class="line">   int c ;</span><br><span class="line"> </span><br><span class="line">   c =  a;</span><br><span class="line">   printf(&quot;Line 1 - =  运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c +=  a;</span><br><span class="line">   printf(&quot;Line 2 - += 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c -=  a;</span><br><span class="line">   printf(&quot;Line 3 - -= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c *=  a;</span><br><span class="line">   printf(&quot;Line 4 - *= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c /=  a;</span><br><span class="line">   printf(&quot;Line 5 - /= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c  = 200;</span><br><span class="line">   c %=  a;</span><br><span class="line">   printf(&quot;Line 6 - %= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c &lt;&lt;=  2;</span><br><span class="line">   printf(&quot;Line 7 - &lt;&lt;= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c &gt;&gt;=  2;</span><br><span class="line">   printf(&quot;Line 8 - &gt;&gt;= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c &amp;=  2;</span><br><span class="line">   printf(&quot;Line 9 - &amp;= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c ^=  2;</span><br><span class="line">   printf(&quot;Line 10 - ^= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">   c |=  2;</span><br><span class="line">   printf(&quot;Line 11 - |= 运算符实例，c 的值 = %d\n&quot;, c );</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - =  运算符实例，c 的值 = 21 <br><br>Line 2 - += 运算符实例，c 的值 = 42 <br><br>Line 3 - -= 运算符实例，c 的值 = 21 <br><br>Line 4 - *= 运算符实例，c 的值 = 441 <br><br>Line 5 - /= 运算符实例，c 的值 = 21 <br><br>Line 6 - %= 运算符实例，c 的值 = 11 <br><br>Line 7 - &lt;&lt;= 运算符实例，c 的值 = 44 <br><br>Line 8 - &gt;&gt;= 运算符实例，c 的值 = 11 <br><br>Line 9 - &amp;= 运算符实例，c 的值 = 2 <br><br>Line 10 - ^= 运算符实例，c 的值 = 0 <br><br>Line 11 - |= 运算符实例，c 的值 = 2 <br></p>
</blockquote>
<hr>
<h4 id="杂项运算符-↦-sizeof-amp-三元"><a href="#杂项运算符-↦-sizeof-amp-三元" class="headerlink" title="杂项运算符 ↦ sizeof &amp; 三元"></a>杂项运算符 ↦ sizeof &amp; 三元</h4><p>下表列出了 C 语言支持的其他一些重要的运算符，包括 sizeof 和 ? :。</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody>
<tr>
<td>sizeof()</td>
<td>返回变量的大小。</td>
<td>sizeof(a) 将返回 4，其中 a 是整数。</td>
</tr>
<tr>
<td>&amp;</td>
<td>返回变量的地址。</td>
<td>&a; 将给出变量的实际地址。</td>
</tr>
<tr>
<td>*</td>
<td>指向一个变量。</td>
<td>*a; 将指向一个变量。</td>
</tr>
<tr>
<td>? :</td>
<td>条件表达式</td>
<td>如果条件为真 ? 则值为 X : 否则值为 Y</td>
</tr>
</tbody>
</table>
<h5 id="实例-5"><a href="#实例-5" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中所有可用的杂项运算符：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 4;</span><br><span class="line">   short b;</span><br><span class="line">   double c;</span><br><span class="line">   int* ptr;</span><br><span class="line"> </span><br><span class="line">   /* sizeof 运算符实例 */</span><br><span class="line">   printf(&quot;Line 1 - 变量 a 的大小 = %lu\n&quot;, sizeof(a) );</span><br><span class="line">   printf(&quot;Line 2 - 变量 b 的大小 = %lu\n&quot;, sizeof(b) );</span><br><span class="line">   printf(&quot;Line 3 - 变量 c 的大小 = %lu\n&quot;, sizeof(c) );</span><br><span class="line"> </span><br><span class="line">   /* &amp; 和 * 运算符实例 */</span><br><span class="line">   ptr = &amp;a;    /* &apos;ptr&apos; 现在包含 &apos;a&apos; 的地址 */</span><br><span class="line">   printf(&quot;a 的值是 %d\n&quot;, a);</span><br><span class="line">   printf(&quot;*ptr 是 %d\n&quot;, *ptr);</span><br><span class="line"> </span><br><span class="line">   /* 三元运算符实例 */</span><br><span class="line">   a = 10;</span><br><span class="line">   b = (a == 1) ? 20: 30;</span><br><span class="line">   printf( &quot;b 的值是 %d\n&quot;, b );</span><br><span class="line"> </span><br><span class="line">   b = (a == 10) ? 20: 30;</span><br><span class="line">   printf( &quot;b 的值是 %d\n&quot;, b );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>Line 1 - 变量 a 的大小 = 4 <br><br>Line 2 - 变量 b 的大小 = 2 <br><br>Line 3 - 变量 c 的大小 = 8 <br><br>a 的值是 4 <br><br>*ptr 是 4 <br><br>b 的值是 30 <br><br>b 的值是 20 <br></p>
</blockquote>
<hr>
<h4 id="C-中的运算符优先级"><a href="#C-中的运算符优先级" class="headerlink" title="C 中的运算符优先级"></a>C 中的运算符优先级</h4><p>运算符的优先级确定表达式中项的组合。这会影响到一个表达式如何计算。某些运算符比其他运算符有更高的优先级，例如，乘除运算符具有比加减运算符更高的优先级。</p>
<p>例如 x = 7 + 3 <em> 2，在这里，x 被赋值为 13，而不是 20，因为运算符 </em> 具有比 + 更高的优先级，所以首先计算乘法 3*2，然后再加上 7。</p>
<p>下表将按运算符优先级从高到低列出各个运算符，具有较高优先级的运算符出现在表格的上面，具有较低优先级的运算符出现在表格的下面。在表达式中，较高优先级的运算符会优先被计算。</p>
<table>
<thead>
<tr>
<th>类别</th>
<th>运算符</th>
<th>结合性</th>
</tr>
</thead>
<tbody>
<tr>
<td>后缀</td>
<td>() [] -&gt; . ++ - -</td>
<td>从左到右 </td>
</tr>
<tr>
<td>一元</td>
<td>+ - ! ~ ++ - - (type)* &amp; sizeof</td>
<td>从右到左 </td>
</tr>
<tr>
<td>乘除</td>
<td>* / %</td>
<td>从左到右</td>
</tr>
<tr>
<td>加减</td>
<td>+ -</td>
<td>从左到右</td>
</tr>
<tr>
<td>移位</td>
<td>&lt;&lt; &gt;&gt;</td>
<td>从左到右</td>
</tr>
<tr>
<td>关系</td>
<td>&lt; &lt;= &gt; &gt;=</td>
<td>从左到右</td>
</tr>
<tr>
<td>相等</td>
<td>==  !=</td>
<td>从左到右</td>
</tr>
<tr>
<td>位与 AND</td>
<td>&amp;</td>
<td>从左到右</td>
</tr>
<tr>
<td>位异或 XOR</td>
<td>^</td>
<td>从左到右</td>
</tr>
<tr>
<td>位或 OR</td>
<td>&#124;</td>
<td>从左到右</td>
</tr>
<tr>
<td>逻辑与 AND</td>
<td>&amp;&amp;</td>
<td>从左到右</td>
</tr>
<tr>
<td>逻辑或 OR</td>
<td>&#124;&#124;</td>
<td>从左到右</td>
</tr>
<tr>
<td>条件</td>
<td>?:</td>
<td>从右到左</td>
</tr>
<tr>
<td>赋值</td>
<td>= += -= *= /= %=&gt;&gt;= &lt;&lt;= &amp;= ^= &#124;=</td>
<td>从右到左</td>
</tr>
<tr>
<td>逗号</td>
<td>,</td>
<td>从左到右</td>
</tr>
</tbody>
</table>
<h5 id="实例-6"><a href="#实例-6" class="headerlink" title="实例"></a>实例</h5><p>请看下面的实例，了解 C 语言中运算符的优先级：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">main()</span><br><span class="line">&#123;</span><br><span class="line">   int a = 20;</span><br><span class="line">   int b = 10;</span><br><span class="line">   int c = 15;</span><br><span class="line">   int d = 5;</span><br><span class="line">   int e;</span><br><span class="line"> </span><br><span class="line">   e = (a + b) * c / d;      // ( 30 * 15 ) / 5</span><br><span class="line">   printf(&quot;(a + b) * c / d 的值是 %d\n&quot;,  e );</span><br><span class="line"> </span><br><span class="line">   e = ((a + b) * c) / d;    // (30 * 15 ) / 5</span><br><span class="line">   printf(&quot;((a + b) * c) / d 的值是 %d\n&quot; ,  e );</span><br><span class="line"> </span><br><span class="line">   e = (a + b) * (c / d);   // (30) * (15/5)</span><br><span class="line">   printf(&quot;(a + b) * (c / d) 的值是 %d\n&quot;,  e );</span><br><span class="line"> </span><br><span class="line">   e = a + (b * c) / d;     //  20 + (150/5)</span><br><span class="line">   printf(&quot;a + (b * c) / d 的值是 %d\n&quot; ,  e );</span><br><span class="line">  </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>(a + b) <em> c / d 的值是 90 <br><br>((a + b) </em> c) / d 的值是 90 <br><br>(a + b) <em> (c / d) 的值是 90 <br><br>a + (b </em> c) / d 的值是 50 <br></p>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/01/08/c08/" rel="next" title="C 存储类">
                <i class="fa fa-chevron-left"></i> C 存储类
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/01/10/c10/" rel="prev" title="C 判断">
                C 判断 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#算术运算符"><span class="nav-number">1.</span> <span class="nav-text">算术运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例"><span class="nav-number">1.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关系运算符"><span class="nav-number">2.</span> <span class="nav-text">关系运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-1"><span class="nav-number">2.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#逻辑运算符"><span class="nav-number">3.</span> <span class="nav-text">逻辑运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-2"><span class="nav-number">3.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#位运算符"><span class="nav-number">4.</span> <span class="nav-text">位运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-3"><span class="nav-number">4.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#赋值运算符"><span class="nav-number">5.</span> <span class="nav-text">赋值运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-4"><span class="nav-number">5.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#杂项运算符-↦-sizeof-amp-三元"><span class="nav-number">6.</span> <span class="nav-text">杂项运算符 ↦ sizeof &amp; 三元</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-5"><span class="nav-number">6.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#C-中的运算符优先级"><span class="nav-number">7.</span> <span class="nav-text">C 中的运算符优先级</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-6"><span class="nav-number">7.1.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
